﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TTSBLL;
using TTSModel;
using TTS;
public partial class ReportingView_PackageSending : System.Web.UI.Page
{
    private Package packageBLL;
    private PackageInfo _packageInfo;
    private string message;
   // private string Pack_DropDownList { get { return ViewState["Pack_DropDownList"].ToString(); } set { ViewState["Pack_DropDownList"] = value; } }
    private string Pack_TextBox1 { get { return ViewState["Pack_TextBox1"].ToString(); } set { ViewState["Pack_TextBox1"] = value; } }
    private string Pack_TextBox2 { get { return ViewState["Pack_TextBox2"].ToString(); } set { ViewState["Pack_TextBox2"] = value; } }
    private string Pack_TextBox3 { get { return ViewState["Pack_TextBox3"].ToString(); } set { ViewState["Pack_TextBox3"] = value; } }
    private string Pack_TextBox4 { get { return ViewState["Pack_TextBox4"].ToString(); } set { ViewState["Pack_TextBox4"] = value; } }
    private string Pack_TextBox5 { get { return ViewState["Pack_TextBox5"].ToString(); } set { ViewState["Pack_TextBox5"] = value; } }
    private string Pack_TextBox6 { get { return ViewState["Pack_TextBox6"].ToString(); } set { ViewState["Pack_TextBox6"] = value; } }
    private int Pack_TextBox7 { get { return Convert.ToInt32(ViewState["Pack_TextBox7"].ToString()); } set { ViewState["Pack_TextBox7"] = value; } }
    private int Pack_TextBox8 { get { return Convert.ToInt32(ViewState["Pack_TextBox8"].ToString()); } set { ViewState["Pack_TextBox8"] = value; } }
    private string Pack_TextBox9 { get { return ViewState["Pack_TextBox9"].ToString(); } set { ViewState["Pack_TextBox9"] = value; } }
    private string Pack_TextBox10 { get { return ViewState["Pack_TextBox10"].ToString(); } set { ViewState["Pack_TextBox10"] = value; } }
    private string Pack_TextBox11 { get { return ViewState["Pack_TextBox11"].ToString(); } set { ViewState["Pack_TextBox11"] = value; } }
    private string Pack_TextBox12 { get { return ViewState["Pack_TextBox12"].ToString(); } set { ViewState["Pack_TextBox12"] = value; } }
    //private string Pack_TextBox13 { get { return ViewState["Pack_TextBox13"].ToString(); } set { ViewState["Pack_TextBox13"] = value; } }
    private string Pack_TextBox13
    { 
        get 
        {
            return ViewState["Pack_TextBox13"] == null ? "" : (string)ViewState["Pack_TextBox13"]; 
        } 
        set { ViewState["Pack_TextBox13"] = value; }
    }
   
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    public ReportingView_PackageSending()
    {
        packageBLL = new Package();
    }
   
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        Pack_TextBox1 = this.TextBox1.Text.Trim();
        if(ProConditionHelper.IsPackageExsit(this.DropDownList2.SelectedValue,Pack_TextBox1,out message))
        {
            TextBox2.Enabled = true;
            TextBox2.Focus();
            return;
        }
        ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
        this.TextBox1.Text = "";
    }
    protected void TextBox2_TextChanged(object sender, EventArgs e)
    {
        
        Pack_TextBox2 = this.TextBox2.Text.Trim();
      if(  ProConditionHelper.IsCorrect(this.DropDownList1.SelectedValue,Pack_TextBox2.Substring(0,8),out message))
      {
          TextBox3.Enabled = true;
          TextBox3.Focus();
          return;
      }
      ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
      this.TextBox2.Text = "";
    }
    protected void TextBox3_TextChanged(object sender, EventArgs e)
    {
        Pack_TextBox3 = this.TextBox3.Text.Trim();

        if (ProConditionHelper.IsCorrect(this.DropDownList1.SelectedValue, Pack_TextBox3, out message))
        {
            TextBox4.Enabled = true;
            TextBox4.Focus();
            return;
        }
        ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
        this.TextBox3.Text = "";
    }
    protected void TextBox4_TextChanged(object sender, EventArgs e)
    {
        Pack_TextBox4 = this.TextBox4.Text.Trim();
        TextBox5.Focus();
    }
    protected void TextBox5_TextChanged(object sender, EventArgs e)
    {
        Pack_TextBox5 = this.TextBox5.Text.Trim();
        if (Pack_TextBox5==Pack_TextBox1)
        {
            TextBox6.Enabled = true;
            TextBox6.Focus();
            return;
        }
        message = "该次输入的KCC与第一个输入框的KCC不一致，请重新输入！";
        ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
        this.TextBox5.Text = "";
    }
    protected void TextBox6_TextChanged(object sender, EventArgs e)
    {
        Pack_TextBox6 = this.TextBox6.Text.Trim();
        TextBox7.Focus();
    }
    protected void TextBox7_TextChanged(object sender, EventArgs e)
    {
        Pack_TextBox7 = Convert.ToInt32(this.TextBox7.Text.Trim());
        TextBox8.Focus();
    }
    protected void TextBox8_TextChanged(object sender, EventArgs e)
    {
        Pack_TextBox8 = Convert.ToInt32(this.TextBox8.Text.Trim());
        TextBox9.Focus();
    }
    protected void TextBox9_TextChanged(object sender, EventArgs e)
    {
        Pack_TextBox9 = this.TextBox9.Text.Trim();
        TextBox10.Focus();
    }
    protected void TextBox10_TextChanged(object sender, EventArgs e)
    {
        Pack_TextBox10 = this.TextBox10.Text.Trim();
        TextBox11.Focus();
    }
    protected void TextBox11_TextChanged(object sender, EventArgs e)
    {
        Pack_TextBox11 = this.TextBox11.Text.Trim();
        TextBox12.Focus();
    }
    protected void TextBox12_TextChanged(object sender, EventArgs e)
    {
        Pack_TextBox12 = this.TextBox12.Text.Trim();
        TextBox13.Focus();
    }
    protected void TextBox13_TextChanged(object sender, EventArgs e)
    {
        Pack_TextBox13 = this.TextBox13.Text.Trim();
        Button1.Focus();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (ProConditionHelper.IsPackageExsit(this.DropDownList2.SelectedValue, Pack_TextBox1, out message))
        {
            if (ProConditionHelper.IsCorrect(this.DropDownList1.SelectedValue, Pack_TextBox2.Substring(0, 8), out message))
            {
                if (ProConditionHelper.IsCorrect(this.DropDownList1.SelectedValue, Pack_TextBox3, out message))
                {
                    if (Pack_TextBox5 == Pack_TextBox1)
                    {
                        _packageInfo = new PackageInfo(this.DropDownList1.SelectedValue, Pack_TextBox1, Pack_TextBox2, Pack_TextBox3, Pack_TextBox4, Pack_TextBox5, Pack_TextBox6, Pack_TextBox7, Pack_TextBox8, Pack_TextBox9, Pack_TextBox10, Pack_TextBox11, Pack_TextBox12, Pack_TextBox13, this.DropDownList2.SelectedValue);
                        packageBLL.Insert(_packageInfo);
                        message = "录入成功！";
                        TextBox1.Text = "";
                        TextBox2.Text = "";
                        TextBox3.Text = "";
                        TextBox4.Text = "";
                        TextBox5.Text = "";
                        TextBox6.Text = "";
                        TextBox7.Text = "";
                        TextBox8.Text = "";
                        TextBox9.Text = "";
                        TextBox10.Text = "";
                        TextBox11.Text = "";
                        TextBox12.Text = "";
                        TextBox13.Text = "";
                    }
                    else
                    {
                        message = "整机KccUP与整机KccSN输入框不一致，请确保一致再提交！";
                    }
                }
               
            }
           
        }
        ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/ReportingView/AssembleReportingHtml.aspx");
    }
  
}